# -*- encoding: utf-8 -*-
USER_BASE_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'interval_type_list': ['day', 'week', 'month'],
    'target_event_id': ['bet_order', 'recharge', 'active', 'withdraw', 'register'],
    'values': [
        {
            "value_id": "active_user",
            "target_value": "_user_id",
            "value_name": "登录帐号",
            "filter": [
                {'term': {'_event_id': 'active'}}
            ],
            "operation": "cardinality",
            "description": "当日登录大厅的用户数量"
        },
        {
            "value_id": "bet_user",
            "target_value": "_user_id",
            "value_name": "投注帐号",
            "filter": [
                {'term': {'_event_id': 'bet_order'}},
                {'term': {'bet_order_user_type': 0}}
            ],
            "operation": "cardinality",
            "description": "当日具下注行为的用户数量"
        },
        {
            "value_id": "recharge_user",
            "target_value": "_user_id",
            "value_name": "充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "operation": "cardinality"
        },
        {
            "value_id": "real_active_user",
            "target_value": "_user_id",
            "value_name": "活跃账号",
            "filter": [
                {"terms": {"_event_id": ["withdraw", "recharge", "bet_order", "active", "register"]}},
            ],
            "not_filter": [
                {'term': {"bet_order_user_type": 1}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        }
        ,
        {
            "value_id": "recharge_margin",
            "value_name": "付费率",
            "value_expr": "recharge_user / real_active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "充值账号 / 活跃账号"
        },
        {
            "value_id": "recharge_amount",
            "target_value": "recharge_price",
            "value_name": "充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "arpu",
            "value_name": "ARPU",
            "value_expr": "recharge_amount/real_active_user",
            "adjust_amount": True,
            "description": "所有活跃账号人均付费金额，付费金额 / 活跃账号"
        },
        {
            "value_id": "arppu",
            "value_name": "ARPPU",
            "value_expr": "recharge_amount/recharge_user",
            "adjust_amount": True,
            "description": "所有付费账号人均付费金额，付费金额 / 付费账号"
        }
    ]
}

USER_NEW_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'interval_type_list': ['day', 'week', 'month'],
    'target_event_id': ['register', 'bet_order', 'recharge', 'bind'],
    'values': [
        {
            "value_id": "register_user",
            "target_value": "_user_id",
            "value_name": "注册账号",
            "filter": [
                {'term': {'_event_id': 'register'}},
            ],
            "operation": "value_count",
            "description": "当日新创建的用户数量"
        },
        {
            "value_id": "new_bind_user",
            "target_value": "_user_id",
            "value_name": "注册绑定账号",
            "filter": [
                {'term': {'_event_id': 'bind'}},
            ],
            "time_range": {
                "_registered_at": [0, 0]
            },
            "operation": "cardinality",
            "description": "当日新创建并绑定手机号的用户数量"
        },
        {
            "value_id": "new_bind_margin",
            "value_name": "新注绑率",
            "value_expr": "new_bind_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新充值账号 / 新用户登录账号"
        },
        {
            "value_id": "new_bet_user",
            "target_value": "_user_id",
            "value_name": "新投注账号",
            "filter": [
                {'term': {'_event_id': 'bet_order'}}
            ],
            "time_range": {
                "_registered_at": [0, 0]
            },
            "operation": "cardinality",
            "description": "当日具下注行为的新用户数量"
        },
        {
            "value_id": "new_bet_margin",
            "value_name": "新投注率",
            "value_expr": "new_bet_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新投注账号 / 新用户登录账号"
        },
        {
            "value_id": "new_recharge_user",
            "target_value": "_user_id",
            "value_name": "新充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "time_range": {
                "_registered_at": [0, 0]
            },
            "operation": "cardinality"
        },
        {
            "value_id": "new_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "新充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "time_range": {
                "_registered_at": [0, 0]
            },
            "adjust_amount": True,
        },
        {
            "value_id": "new_recharge_margin",
            "value_name": "新付费率",
            "value_expr": "new_recharge_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新充值账号 / 新用户登录账号"
        },
        {
            "value_id": "new_arpu",
            "value_name": "新ARPU",
            "value_expr": "new_recharge_amount/register_user",
            "adjust_amount": True,
            "description": "新用户活跃账号人均付费金额，新付费金额 / 新活跃账号"
        },
        {
            "value_id": "new_arppu",
            "value_name": "新ARPPU",
            "value_expr": "new_recharge_amount/new_recharge_user",
            "adjust_amount": True,
            "description": "新用户付费账号人均付费金额，新付费金额 / 新付费账号"
        }
    ]
}

USER_STAY_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'interval_type_list': ['day'],
    'day_to_calc': range(0, 60),
    'target_event_id': ['register', 'recharge', 'bind', 'active'],
    'values': [
        {
            "value_id": "register_user",
            "target_value": "_user_id",
            "value_name": "注册账号",
            "filter": [
                {'term': {'_event_id': 'register'}},
            ],
            "operation": "value_count",
            "description": "当日新创建的用户数量",
            "hide_result": True
        },
        {
            "value_id": "stay_2_user",
            "target_value": "_user_id",
            "value_name": "次日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality",
            "hide_result": True,
            "description": "新增后第二天登录的账号／首日新增账号"
        },
        {
            "value_id": "stay_3_user",
            "target_value": "_user_id",
            "value_name": "3日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 2}}
            ],
            "time_range": {
                "_event_time": [2, 2]
            },
            "operation": "cardinality",
            "hide_result": True
        },
        {
            "value_id": "stay_7_user",
            "target_value": "_user_id",
            "value_name": "7日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 6}}
            ],
            "time_range": {
                "_event_time": [6, 6]
            },
            "operation": "cardinality",
            "hide_result": True
        },
        {
            "value_id": "stay_user_rate_2",
            "value_name": "次日留存",
            "value_expr": "stay_2_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第二天登录的账号／首日新增账号"
        },
        {
            "value_id": "stay_user_rate_3",
            "value_name": "3日留存",
            "value_expr": "stay_3_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第三天登录的账号／首日新增账号"
        },
        {
            "value_id": "stay_user_rate_7",
            "value_name": "7日留存",
            "value_expr": "stay_7_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第七天登录的账号／首日新增账号"
        },
        {
            "value_id": "ltv7_recharge",
            "target_value": "recharge_price",
            "value_name": "6天前新增用户累计充值金额",
            "time_range": {
                "_event_time": [-6, 0],
                "_registered_at": [-6, -6]
            },
            "filter": [
                {"term": {"_event_id": "recharge"}}
            ],
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "ltv14_recharge",
            "target_value": "recharge_price",
            "value_name": "13天前新增用户累计充值金额",
            "time_range": {
                "_event_time": [-13, 0],
                "_registered_at": [-13, -13]
            },
            "filter": [
                {"term": {"_event_id": "recharge"}}
            ],
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "ltv30_recharge",
            "target_value": "recharge_price",
            "value_name": "29天前新增用户累计充值金额",
            "time_range": {
                "_event_time": [-29, 0],
                "_registered_at": [-29, -29]
            },
            "filter": [
                {"term": {"_event_id": "recharge"}}
            ],
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "ltv60_recharge",
            "target_value": "recharge_price",
            "value_name": "59天前新增用户累计充值金额",
            "time_range": {
                "_event_time": [-59, 0],
                "_registered_at": [-59, -59]
            },
            "filter": [
                {"term": {"_event_id": "recharge"}}
            ],
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "ltv7_user",
            "target_value": "_user_id",
            "value_name": "6天前新增用户数",
            "time_range": {
                "_event_time": [-6, -6],
            },
            "filter": [
                {"term": {"_event_id": "register"}}
            ],
            "operation": "cardinality",
            "hide_result": True
        },
        {
            "value_id": "ltv14_user",
            "target_value": "_user_id",
            "value_name": "13天前新增用户数",
            "time_range": {
                "_event_time": [-13, -13],
            },
            "filter": [
                {"term": {"_event_id": "register"}}
            ],
            "operation": "cardinality",
            "hide_result": True
        },
        {
            "value_id": "ltv30_user",
            "target_value": "_user_id",
            "value_name": "29天前新增用户数",
            "time_range": {
                "_event_time": [-29, -29]
            },
            "filter": [
                {"term": {"_event_id": "register"}}
            ],
            "operation": "cardinality",
            "hide_result": True
        },
        {
            "value_id": "ltv60_user",
            "target_value": "_user_id",
            "value_name": "59天前新增用户数",
            "time_range": {
                "_event_time": [-59, -59],
            },
            "filter": [
                {"term": {"_event_id": "register"}}
            ],
            "operation": "cardinality",
            "hide_result": True
        },
        {
            "value_id": "ltv7",
            "value_name": "7日LTV",
            "value_expr": "ltv7_recharge/ltv7_user",
            "adjust_amount": True,
            "description": "当日用户七日累计付费金额／首日新增账号"
        },
        {
            "value_id": "ltv14",
            "value_name": "14日LTV",
            "value_expr": "ltv14_recharge/ltv14_user",
            "adjust_amount": True,
            "description": "当日用户十四日累计付费金额／首日新增账号"
        },
        {
            "value_id": "ltv30",
            "value_name": "30日LTV",
            "value_expr": "ltv30_recharge/ltv30_user",
            "adjust_amount": True,
            "description": "当日用户三十日累计付费金额／首日新增账号"
        },
        {
            "value_id": "ltv60",
            "value_name": "60日LTV",
            "value_expr": "ltv60_recharge/ltv60_user",
            "adjust_amount": True,
            "description": "当日用户六十日累计付费金额／首日新增账号"
        }
    ]
}
